package com.ruoyi.xsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xsp.domain.XspNewsInfo;
import com.ruoyi.xsp.service.IXspNewsInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 视频管理Controller
 * 
 * @author zhiminhu
 * @date 2021-01-22
 */
@Controller
@RequestMapping("/xsp/info")
public class XspNewsInfoController extends BaseController
{
    private String prefix = "xsp/info";

    @Autowired
    private IXspNewsInfoService xspNewsInfoService;

    @RequiresPermissions("xsp:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询视频管理列表
     */
    @RequiresPermissions("xsp:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(XspNewsInfo xspNewsInfo)
    {
        startPage();
        List<XspNewsInfo> list = xspNewsInfoService.selectXspNewsInfoList(xspNewsInfo);
        return getDataTable(list);
    }

    /**
     * 导出视频管理列表
     */
    @RequiresPermissions("xsp:info:export")
    @Log(title = "视频管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(XspNewsInfo xspNewsInfo)
    {
        List<XspNewsInfo> list = xspNewsInfoService.selectXspNewsInfoList(xspNewsInfo);
        ExcelUtil<XspNewsInfo> util = new ExcelUtil<XspNewsInfo>(XspNewsInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增视频管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存视频管理
     */
    @RequiresPermissions("xsp:info:add")
    @Log(title = "视频管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(XspNewsInfo xspNewsInfo)
    {
        return toAjax(xspNewsInfoService.insertXspNewsInfo(xspNewsInfo));
    }

    /**
     * 修改视频管理
     */
    @GetMapping("/edit/{newsId}")
    public String edit(@PathVariable("newsId") Long newsId, ModelMap mmap)
    {
        XspNewsInfo xspNewsInfo = xspNewsInfoService.selectXspNewsInfoById(newsId);
        mmap.put("xspNewsInfo", xspNewsInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存视频管理
     */
    @RequiresPermissions("xsp:info:edit")
    @Log(title = "视频管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(XspNewsInfo xspNewsInfo)
    {
        return toAjax(xspNewsInfoService.updateXspNewsInfo(xspNewsInfo));
    }

    /**
     * 删除视频管理
     */
    @RequiresPermissions("xsp:info:remove")
    @Log(title = "视频管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(xspNewsInfoService.deleteXspNewsInfoByIds(ids));
    }
}
